

using System;
using System.Runtime.InteropServices;

namespace CUtil.Win32
{
	/// <summary> 
	/// Helper class containing wrappers for some WinApi Olepro32 functions 
	/// 
	/// </summary>
	[System.Security.SuppressUnmanagedCodeSecurity()]
	public class Olepro32
	{
		/// <summary> 
		/// Do not create instances of this class!
		/// </summary>
		private Olepro32(){}

#region enums
#endregion enums
				
#region constants
		/// <summary>Definition in file afxres.h </summary>
		public const int PICTYPE_BITMAP		= 1;
		
		/// <summary>Definition in file afxres.h </summary>
		public const int PICTYPE_ICON		= 3;

		/// <summary>Definition in file Ocidl.idl </summary>
		public static Guid UUID_IPicture = new Guid("7BF80980-BF32-101A-8BBB-00AA00300CAB");
#endregion constants

#region structs
		/// <summary>
		/// To bitmaps specialized struct of Win32 union PICTDESC.
		/// </summary>
		[StructLayout(LayoutKind.Sequential, Pack=1 )]
		public struct PICTDESCBITMAP
		{
			/// <summary> See Win32 struct: PICTDESC </summary>
			public uint cbSizeofstruct; 
			/// <summary> See Win32 struct: PICTDESC </summary>
			public uint picType; 
			/// <summary> See Win32 struct: PICTDESC </summary>
			public IntPtr hbitmap;
			/// <summary> See Win32 struct: PICTDESC </summary>
			public IntPtr hpal;
		}

		/// <summary>
		/// To icons specialized struct of Win32 union PICTDESC.
		/// </summary>
		[StructLayout(LayoutKind.Sequential, Pack=1)]
		public struct PICTDESCICON
		{
			/// <summary> See Win32 struct: PICTDESC </summary>
			public uint cbSizeofstruct; 
			/// <summary> See Win32 struct: PICTDESC </summary>
			public uint picType; 
			/// <summary> See Win32 struct: PICTDESC </summary>
			public IntPtr hicon;
		}
#endregion structs

#region functions
		/// <summary>
		/// Creates an IPicture Pointer from the bitmap handle in pDesc
		/// </summary>
		[DllImport("olepro32.dll",PreserveSig=false)]
		public static extern void OleCreatePictureIndirect(
			ref PICTDESCBITMAP pDesc,
			ref Guid refiid,
			bool fOwn,
			[MarshalAs(UnmanagedType.IUnknown)]out Object lplpvObject);

		/// <summary>
		/// Creates an IPicture Pointer from the icon handle in pDesc
		/// </summary>
		[DllImport("olepro32.dll",PreserveSig=false)]
		public static extern void OleCreatePictureIndirect(
			ref PICTDESCICON pDesc,
			ref Guid refiid,
			bool fOwn,
			[MarshalAs(UnmanagedType.IUnknown)]out Object lplpvObject);
#endregion functions
	}
}
